package jdk8.lambda;

import java.util.Arrays;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PredicateDemo {

	public static void main(String[] args) {
		Predicate<String> pstr = new Predicate<String>() {
			
			@Override
			public boolean test(String t) {
				//
				return t == null || t.trim().length() == 0;
			}
		};
		//
		System.out.println(pstr.test(null));
		System.out.println(pstr.test("  "));
		System.out.println(pstr.test(" a "));
		//
		System.out.println("----- Lambda表达式改写 =================");
		//Predicate<Object> pobj = Objects::isNull;
		Predicate<Object> pobj = (t) -> t == null;
		System.out.println(pobj.test("abc"));
		
		//
		int[] arr = {-1,4,15,8,5,-2,-19,-34,345,6453,2342,-324,-24,19};
		//统计出这个整型数组中正数的个数
		long count = Arrays.stream(arr).filter((t) -> t > 0 ).count();
		System.out.println(count);
		Arrays.stream(arr).filter( (t) -> t > 0).forEach(System.out::println);
	}
}
